import { SkuData, SkuInfoData, SkuResponseData } from './types';

// 统一接口管理
enum API {
  GET_SKU_URL = '/admin/product/list',
  GET_ATTRINFOLIST_URL = '/admin/product/attrInfoList',
  GET_SPUIMAGELIST_URL = '/admin/product/spuImageList',
  GET_SPUSALEATTRLIST_URL = '/admin/product/spuSaleAttrList',

  GET_SKU_BYSPUID_URL = '/admin/product/findBySpuId',

  ADD_SKU_URL = '/admin/product/saveSkuInfo',
  UPDATE_SKU_URL = '/admin/product/updateSkuInfo',
  DELETE_SKU_URL = '/admin/product/deleteSku',
  GET_SKUINFO_URL = '/admin/product/getSkuInfo',

  BOTTOM_Sale_URL = '/admin/product/cancelSale',
  TOP_Sale_URL = '/admin/product/onSale',
}
/**
 * 分页获得sku数据
 * @param page 页码
 * @param limit 页面大小
 * @returns
 */
export const reqGetSku = (page: number, limit: number) => {
  return request.get<any, SkuResponseData>(API.GET_SKU_URL + `/${page}/${limit}`);
};
/**
 * 根据spuId获取该spu的所有sku
 * @param spuId
 * @returns
 */
export const reqGetSkuBySpuId = (spuId: number) => {
  return request.get<any, SkuInfoData>(API.GET_SKU_BYSPUID_URL + `/${spuId}`);
};
/**
 * 根据三级分类id获取商品属性
 * @param category1Id
 * @param category2Id
 * @param category3Id
 * @returns
 */
export const reqGetAttrInfos = (category1Id: string | number, category2Id: string | number, category3Id: string | number) => {
  return request.get<any, any>(API.GET_ATTRINFOLIST_URL + `/${category1Id}/${category2Id}/${category3Id}`);
};
/**
 * 获得spu图片列表
 * @param spuId
 * @returns
 */
export const reqGetSpuImages = (spuId: number) => {
  return request.get<any, any>(API.GET_SPUIMAGELIST_URL + `/${spuId}`);
};
/**
 * 获得销售属性列表
 * @param spuId
 * @returns
 */
export const reqGetSpuSaleAttrs = (spuId: number) => {
  return request.get<any, any>(API.GET_SPUSALEATTRLIST_URL + `/${spuId}`);
};
/**
 *
 * @param data 添加或者修改商品
 * @returns
 */
export const reqAddOrUpdateSku = (data: SkuData) => {
  if (data.id) {
    return request.post<any, any>(API.UPDATE_SKU_URL, data);
  } else {
    return request.post<any, any>(API.ADD_SKU_URL, data);
  }
};
/**
 * 删除sku
 * @param skuId
 * @returns
 */
export const reqDeleteSku = (skuId: number) => {
  return request.delete<any, any>(API.DELETE_SKU_URL + `/${skuId}`);
};
/**
 * 获得sku商品详情信息
 * @param skuId
 * @returns
 */
export const reqGetSkuInfo = (skuId: number) => {
  return request.get<any, any>(API.GET_SKUINFO_URL + `/${skuId}`);
};
/**
 * 商品上架
 * @param spuId
 * @returns
 */
export const reqSkuBottomSale = (spuId: number) => {
  return request.get<any, any>(API.BOTTOM_Sale_URL + `/${spuId}`);
};
/**
 * 商品下架
 * @param spuId
 * @returns
 */
export const reqSkuTopSale = (spuId: number) => {
  return request.get<any, any>(API.TOP_Sale_URL + `/${spuId}`);
};
